# encoding: utf-8
# Datetime  : 2020/6/2 7:48 PM
# User      : zzz
# File      : proxy_test.py
import requests

from util import proxy_util


def delete_proxy(proxy):
    requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))


# your spider code

def getHtml():
    # ....
    retry_count = 5
    proxy = proxy_util.get_proxy()
    while retry_count > 0:
        try:
            html = requests.get('http://www.example.com', proxies=proxy)
            # 使用代理访问
            return html
        except Exception:
            retry_count -= 1
    # 出错5次, 删除代理池中代理
    delete_proxy(proxy)
    return None


if __name__ == '__main__':
    html = getHtml()
    print(html)
